package com.example.danangtravel;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Spinner;

public class Tbshoping_activity extends Activity {
	public Spinner spinner;
	public ArrayAdapter<String> array;
	public TbShoppingAdapter adapter;
	public List<Tbshopping> list;
	public ListView listview;
	public DataAccess dataaccess;
	public ImageButton btnhome;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_tbshoping_activity);
		final String[] a = { "Hệ thống Siêu thị", "Hệ thống Chợ",
				"Hệ thống Cửa hàng" };
		listview = (ListView) findViewById(R.id.listView1);
		spinner = (Spinner) findViewById(R.id.spinner1);
		array = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, a);
		array.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
		spinner.setAdapter(array);
		spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				// TODO Auto-generated method stub
				list = new ArrayList<Tbshopping>();
				if (arg2 == 0) {
					list = dataaccess.getAllShopping_sieuthi();
				}
				;
				if (arg2 == 1) {
					list = dataaccess.getAllShopping_cho();
				}
				;
				if (arg2 == 2) {
					list = dataaccess.getAllShopping_cuahang();
				}
				;

				adapter = new TbShoppingAdapter(arg1.getContext(), list);
				listview.setAdapter(adapter);
				listview.setOnItemClickListener(new OnItemClickListener() {

					public void onItemClick(AdapterView<?> arg0, View arg1,
							int arg2, long arg3) {
						// TODO Auto-generated method stub
						Toast.makeText(arg1.getContext(), "ok", 1000).show();
					}
				});
			}

			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub

			}
		});
		btnhome = (ImageButton) findViewById(R.id.btnhom);
		btnhome.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				finish();
			}
		});
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		try {
			dataaccess = new DataAccess(this);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		dataaccess.open();
	}
}
